package com.tac.controller;


import com.tac.common.result.Result;
import com.tac.pojo.Collection;
import com.tac.pojo.Product;
import com.tac.service.CollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/collection")
@Api(value = "收藏",tags ="收藏" )
public class CollectionController {
    @Autowired
    private CollectionService collectionService;
    /**
     * 添加收藏
     * @param pid
     * @return
     */
    @ResponseStatus(HttpStatus.CREATED)
    @PostMapping("/{pid}")
    @ApiOperation("添加收藏")
    public Result save(@PathVariable Integer pid){
      return   collectionService.save(pid);
    }

    /**
     * 删除收藏
     * @param
     * @return
     */
    @ApiOperation("删除收藏")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    @DeleteMapping("/{pid}")
    public Result remove(@PathVariable Integer pid){
        return collectionService.remove(pid);
    }

    /**
     * 查看收藏所有商品 按时间倒序排列
     * @param
     * @return
     */
    @ApiOperation("查看收藏所有商品")
    @GetMapping
    public Result<List<Product>> selectByUid(){
        return collectionService.selectByUid();
    }
    /**
     * 管理员查看收藏所有商品 按时间倒序排列
     * @param
     * @return
     */
    @GetMapping("/selectAll")
    @ApiOperation("管理员查看收藏所有商品")
    public Result<List<Collection>> selectAll(){
        return collectionService.selectAll();
    }
    /**
     * 管理员删除收藏
     * @param pid
     * @param uid
     * @return
     */
    @DeleteMapping("/{pid}/{uid}")
    @ApiOperation("管理员删除收藏")
    @ResponseStatus(HttpStatus.NO_CONTENT)
    public Result delete(@PathVariable Integer pid,@PathVariable Integer uid){
        return collectionService.delete(pid,uid);
    }
}
